<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>有效的正方形</title>
</head>
<body>
  <script>
    var res = [
      [0, 0],
      [1, 1],
      [1, 0],
      [0, 1],
    ]
    function num(p1, p2){
      let a = p1[0] - p2[0];
      let b = p1[1] - p2[1];
      return Math.sqrt(a * a + b * b);
    }
    function fn(p1, p2, p3, p4) {
        let arr = [];
        let d12 = num(p1,p2);
        let d13 = num(p1,p3)
        let d14 = num(p1,p4);
        let d23 = num(p2,p3);
        let d24 = num(p2,p4);
        let d34 = num(p3,p4);
        arr = [d12, d13, d14, d23, d24, d34];
        arr.sort((a,b)=> a-b);
        return arr[0] == arr[3] && arr[4] == arr[5] && arr[3] < arr[4];
    }
    console.log(fn(res[0], res[1], res[2], res[3]));
  </script>
</body>
</html>